<%@include file="/WEB-INF/jsp/include/importAndtag.inc"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	
	<title><s:text name="Login"/></title>
	<%@include file="/WEB-INF/jsp/include/pageHeader.inc"%>
	<style type="text/css">
	</style>
	
	<script type="text/javascript">
	
	$(document).ready(function() {
		$(document).keyup(function(event){
		   	if(event.keyCode==13) {
		   		$("#loginBtn").trigger("click");
		   	}
	   	});
	});

	
	function loginSubmit() {
	 	var form = document.loginForm;
	 	var username = $.trim($("#username").val());
	    var paw = $.trim($("#password").val());
	    
	    //validate the username and password
	    if (username == null || username ==''){
	    	showErrorMessage("<s:text name='msg.username.input'/>");
	        return ;
	    }
	    if (paw == null || paw ==''){
	    	showErrorMessage("<s:text name='msg.userpaw.input'/>");
	        return ;
	    }
	    
	    //login
	    $("#loginBtn").html('<s:text name="Logining"/>&nbsp;<span class="ani_dot">...</span>');
	     $.post("${pageContext.request.contextPath}/loginSubmit.action",{"loginType":"ADMIN_LOGIN","user.shortName":username,"user.password":paw},function(data){
	     	if(data!=null){
	     		if(data.OPERATE_SUCCESS != null && data.OPERATE_SUCCESS == true){
	     			var visitUrl = "${pageContext.request.contextPath}/admin/dashboard.action";
	     			
	     			window.location.href = visitUrl;
	     		}else{
	     			showErrorMessage(data.ERROR_MSG);
	     		}
	     	}
	     });
	}
	
	function showErrorMessage(errorMessage){
		$(".passwd-div span.errormsg").remove();
		if(errorMessage != null && $.trim(errorMessage).length>0){
			$(".passwd-div").append('<span role="alert" class="errormsg" id="errormsg_0_Passwd">'+errorMessage+'</span>');
		}
		$("#loginBtn").html('<s:text name="ui_Login"/>');
	}
	</script>
</head>

<body>
<div style="">
<%@include file="../include/bodyHeader.inc" %>
<h1>Admin login</h1>
<div style="clear:both; display:block; height:100px"></div>
<div class="main">

	<!-- login form -->
	<form name="loginForm" id="loginForm"  method="post" novalidate="novalidate">
		<div class="email-div">
		  <label for="Email"><strong class="email-label"><s:text name="UserName"/></strong></label>
		  <input name="user.shortName" type="text" id="username"/>
		</div>
		<div class="passwd-div">
		  <label for="Passwd"><strong class="passwd-label"><s:text name="Password" /></strong></label>
		  <input name="user.password" type="password" id="password" style="margin-right:10px;"/>
		</div>
	    <a id="loginBtn" href="#" class="btn1" onclick="loginSubmit();return false;" style="float:left;" ><s:text name="Login"/></a>
	</form>
</div>
<div style="clear:both; display:block; height:100px"></div>
<%@include file="../include/pageFooter.inc" %>
</div>
</body>
</html>	